<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<title>搜索页面</title>
        <script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/axios.min.js"></script>
		<script type="text/javascript" src="../static/global.js"></script>
		<link href="../AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
		<link href="../AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css" />

		<link href="../basic/css/demo.css" rel="stylesheet" type="text/css" />

		<link href="../css/seastyle.css" rel="stylesheet" type="text/css" />

		<script type="text/javascript" src="../basic/js/jquery-1.7.min.js"></script>
		<script type="text/javascript" src="../js/script.js"></script>
                <script type="text/javascript" src="../elements/element.js"></script>
		<link href="../elements/element.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
	<div id="searchdiv">

		<!--顶部导航条 -->
		<div class="am-container header">
			<ul class="message-l">
				<div class="topMessage">
					<div class="menu-hd">
						<a href="#" target="_top" class="h">亲，请登录</a>
						<a href="#" target="_top">免费注册</a>
					</div>
				</div>
			</ul>
			<ul class="message-r">
				<div class="topMessage home">
					<div class="menu-hd"><a href="#" target="_top" class="h">商城首页</a></div>
				</div>
				<div class="topMessage my-shangcheng">
					<div class="menu-hd MyShangcheng"><a href="#" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a></div>
				</div>
				<div class="topMessage mini-cart">
					<div class="menu-hd"><a id="mc-menu-hd" href="#" target="_top"><i class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum" class="h">0</strong></a></div>
				</div>
				<div class="topMessage favorite">
					<div class="menu-hd"><a href="#" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a></div>
			</ul>
			</div>

			<!--悬浮搜索框-->

			<div class="nav white">
				<div class="logo"><img src="../images/logo.png" /></div>
				<div class="logoBig">
					<li><img src="../images/logobig.png" /></li>
				</div>

				<div class="search-bar pr">
					<a name="index_none_header_sysc" href="#"></a>
					<form>
						<input id="keyword" name="index_none_header_sysc" type="text" placeholder="搜索" autocomplete="off">
						<input id="ai-topsearch" @click.prevent="searchKey" class="submit am-btn"  value="搜索" index="1" type="submit">
					</form>
				</div>
			</div>

			<div class="clear"></div>
			<b class="line"></b>
           <div class="search">
			<div class="search-list">
			<div class="nav-table">
					   <div class="long-title"><span class="all-goods">全部分类</span></div>
					   <div class="nav-cont">
							<ul>
								<li class="index"><a href="#">首页</a></li>
                                <li class="qc"><a href="#">闪购</a></li>
                                <li class="qc"><a href="#">限时抢</a></li>
                                <li class="qc"><a href="#">团购</a></li>
                                <li class="qc last"><a href="#">大包装</a></li>
							</ul>
						    <div class="nav-extra">
						    	<i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
						    	<i class="am-icon-angle-right" style="padding-left: 10px;"></i>
						    </div>
						</div>
			</div>
			
				
					<div class="am-g am-g-fixed">
						<div class="am-u-sm-12 am-u-md-12">
	                  	<div class="theme-popover">														
							<div class="searchAbout">
								<span class="font-pale">相关搜索：</span>
                               <span id="brandOrCatelog"></span>
								<span v-for="resultNavs in result.navs">

								<el-tag class="eltag"  title="123" closable   @close="onCrumbs(resultNavs)" v-model="result.navs" type="danger" closable ><span>{{resultNavs.navName}}</span>:<span style="color: #b2e2fa">{{resultNavs.navValue | ellipsis}} </span></el-tag>
									&nbsp;&nbsp;&nbsp;
                                	</span>
							</div>
							<ul class="select">
								<p class="title font-normal">
									<span class="fl"></span>
									<span class="total fl">搜索到<strong class="num">{{result.total}}</strong>件相关商品</span>
								</p>
								<div class="clear"></div>
								<li class="select-list">
									<dl>
										<dt style="display: none" id="ddyixuan" class="am-badge am-round">已选</dt>
										<div id="ddvalue">

										</div>
										<p class="eliminateCriteria">清除</p>
									</dl>
								</li>
								<div class="clear"></div>
								<li class="select-list" v-for="dataresult in result.attrs">
									<dl id="select1" class="attr">
										<dt class="am-badge am-round">{{dataresult.attrName}}</dt>
										 <div class="dd-conent">

											 <div v-for="dataresultValue in dataresult.attrValue">
												 <dd class="attrValue"><a href="#">{{dataresultValue}}</a>
													 <span style="display: none">{{dataresult.attrId}}</span>
												 </dd>

											 </div>

										 </div>
						
									</dl>
									<hr>
								</li>

							</ul>
							<div class="clear"></div>
                        </div>
							<div class="search-content">
								<div id="sort" class="sort">
									<li class="skusort"><a title="综合" href="#">综合排序</a></li>
									<li class="skusort"><a title="销量" href="#">销量排序</a></li>
									<li class="skusort"><a title="价格" href="#">价格优先</a></li>
									<li class="skusort"><a title="评价" href="#">评价为主</a></li>
								</div>
								<div class="clear"></div>

								<ul class="am-avg-sm-2 am-avg-md-3 am-avg-lg-4 boxes"  >

									<li v-for="resultdata in result.products">
										<div class="i-pic limit">
											<a :href="'introduction.html?skuId='+resultdata.skuId">
											<img style="width: 330px;height: 330px" v-bind:src="resultdata.skuImg"/>
											<p class="title fl" v-html="resultdata.skuTitle"></p>
											<p class="price fl">
												<b>¥</b>
												<strong>{{resultdata.skuPrice}}</strong>
											</p>
											<p class="number fl">
												销量<span>{{resultdata.saleCount}}</span>
											</p>
											</a>
										</div>
									</li>
								</ul>
							</div>
							<div class="search-side">

								<div class="side-title">
									经典搭配
								</div>

								<li v-for="resultsan in resultskuSan">
									<div class="i-pic check">
										<a :href="'introduction.html?skuId='+resultsan.sku_id">
										<img v-bind:src="resultsan.sku_default_img" style="width: 240px;height: 240px" />
										<p class="check-title">{{resultsan.sku_name}}</p>
										<p class="price fl">
											<b>¥</b>
											<strong>{{resultsan.price}}</strong>
										</p>
										<p class="number fl">
											销量<span>{{resultsan.sale_count}}</span>
										</p>
										</a>
									</div>
								</li>



							</div>
							<div class="clear"></div>
							<!--分页 -->
							<el-pagination
									background
									layout="prev, pager, next"
									:total="result.total"
							         @current-change="pagechange"
									page-size="8"
									  >
							</el-pagination>

						</div>
					</div>
					<div class="footer">
						<div class="footer-hd">
							<p>
								<a href="#">恒望科技</a>
								<b>|</b>
								<a href="#">商城首页</a>
								<b>|</b>
								<a href="#">支付宝</a>
								<b>|</b>
								<a href="#">物流</a>
							</p>
						</div>
						<div class="footer-bd">
							<p>
								<a href="#">关于恒望</a>
								<a href="#">合作伙伴</a>
								<a href="#">联系我们</a>
								<a href="#">网站地图</a>
								<em>© 2015-2025 Hengwang.com 版权所有</em>
							</p>
						</div>
					</div>
				</div>

			</div>

		<!--引导 -->
		<div class="navCir">
			<li><a href="home.html"><i class="am-icon-home "></i>首页</a></li>
			<li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
			<li><a href="shopcart.html"><i class="am-icon-shopping-basket"></i>购物车</a></li>	
			<li><a href="../person/index.html"><i class="am-icon-user"></i>我的</a></li>					
		</div>

		<!--菜单 -->
		<div class=tip>
			<div id="sidebar">
				<div id="wrap">
					<div id="prof" class="item">
						<a href="#">
							<span class="setting"></span>
						</a>
						<div class="ibar_login_box status_login">
							<div class="avatar_box">
								<p class="avatar_imgbox"><img src="../images/no-img_mid_.jpg" /></p>
								<ul class="user_info">
									<li>用户名：sl1903</li>
									<li>级&nbsp;别：普通会员</li>
								</ul>
							</div>
							<div class="login_btnbox">
								<a href="#" class="login_order">我的订单</a>
								<a href="#" class="login_favorite">我的收藏</a>
							</div>
							<i class="icon_arrow_white"></i>
						</div>

					</div>
					<div id="shopCart" class="item">
						<a href="#">
							<span class="message"></span>
						</a>
						<p>
							购物车
						</p>
						<p class="cart_num">0</p>
					</div>
					<div id="asset" class="item">
						<a href="#">
							<span class="view"></span>
						</a>
						<div class="mp_tooltip">
							我的资产
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div id="foot" class="item">
						<a href="#">
							<span class="zuji"></span>
						</a>
						<div class="mp_tooltip">
							我的足迹
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div id="brand" class="item">
						<a href="#">
							<span class="wdsc"><img src="../images/wdsc.png" /></span>
						</a>
						<div class="mp_tooltip">
							我的收藏
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div id="broadcast" class="item">
						<a href="#">
							<span class="chongzhi"><img src="../images/chongzhi.png" /></span>
						</a>
						<div class="mp_tooltip">
							我要充值
							<i class="icon_arrow_right_black"></i>
						</div>
					</div>

					<div class="quick_toggle">
						<li class="qtitem">
							<a href="#"><span class="kfzx"></span></a>
							<div class="mp_tooltip">客服中心<i class="icon_arrow_right_black"></i></div>
						</li>
						<!--二维码 -->
						<li class="qtitem">
							<a href="#none"><span class="mpbtn_qrcode"></span></a>
							<div class="mp_qrcode" style="display:none;"><img src="../images/weixin_code_145.png" /><i class="icon_arrow_white"></i></div>
						</li>
						<li class="qtitem">
							<a href="#top" class="return_top"><span class="top"></span></a>
						</li>
					</div>

					<!--回到顶部 -->
					<div id="quick_links_pop" class="quick_links_pop hide"></div>

				</div>

			</div>
			<div id="prof-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					我
				</div>
			</div>
			<div id="shopCart-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					购物车
				</div>
			</div>
			<div id="asset-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					资产
				</div>

				<div class="ia-head-list">
					<a href="#" target="_blank" class="pl">
						<div class="num">0</div>
						<div class="text">优惠券</div>
					</a>
					<a href="#" target="_blank" class="pl">
						<div class="num">0</div>
						<div class="text">红包</div>
					</a>
					<a href="#" target="_blank" class="pl money">
						<div class="num">￥0</div>
						<div class="text">余额</div>
					</a>
				</div>

			</div>
			<div id="foot-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					足迹
				</div>
			</div>
			<div id="brand-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					收藏
				</div>
			</div>
			<div id="broadcast-content" class="nav-content">
				<div class="nav-con-close">
					<i class="am-icon-angle-right am-icon-fw"></i>
				</div>
				<div>
					充值
				</div>
			</div>
		</div>
		<script>
			window.jQuery || document.write('&lt;script src="basic/js/jquery-1.9.min.js">&lt;\/script>');
		</script>
		<script type="text/javascript" src="../basic/js/quick_links.js"></script>

<div class="theme-popover-mask"></div>
	</div>
	</body>


</html>
<script>
	var str=[];
	var attrs="";
	var vue1;
	$(function (){
		//接收其他页面传来的值
		let homeUrl=decodeURI(location.search);
		     let params=homeUrl.split("=")[0];
		     let  values=homeUrl.split("=")[1];
		     let homeCatalog3Id="";//前台分类
		     let homeBrandId="";//前台品牌
		//alert(params+":::"+values);
		if(params==="?catalog3Id"){
			// alert("分类");
			 $('#brandOrCatelog').html('<el-tag closable @close="onHome">分类:'+values+'</el-tag>');
			homeCatalog3Id=params+"="+values;
		}else if(params==="?keyword"){
		//	alert("搜索");
			$('#keyword').val(values);
		}else if(params==="?brandId"){
			//alert("品牌");
			$('#brandOrCatelog').html('<el-tag closable @close="onHome">品牌:'+values+'</el-tag>');
			homeBrandId=params+"="+values;
		}


		 vue1=new Vue({
			el:"#searchdiv",
			data:{

				result:[],//返回的商品
				resultskuSan:[],//返回的猜你喜欢等
				url:'',//地址


			},
			 filters: {
				 ellipsis(value) {
					 if (!value) return "";
					 if (value.length > 10) {
						 return value.slice(0, 10) + "...";
					 }
					 return value;
				 }
			 },
			 created(){
				this.searchKey();//执行搜索
			 },
			methods:{
				searchKey()
				{
					//先判断前台的分类值
					if(homeCatalog3Id!=""){
						this.url+=homeCatalog3Id;
					//	alert("分类存在");
					}
					//先判断前台的品牌值
					if(homeBrandId!=""){
						this.url+=homeBrandId;
						//alert("品牌存在")
					}

				//	alert(str);
					//var keyword=this.keyWord;
					//获取已选的属性值
					var attrvalue="";
					var dd=$('#ddvalue').children("dd");
                     // console.log(dd);
                      let str=[];
                      let array=[];
					for(var i=0;i<dd.length;i++){
						let str1={
							 attrId:dd[i].title,
							attrValues:dd[i].textContent
						}
                      str.push(str1);


						/*  判断str里的值和当前选中值的id是否相同

						* for(var j=0;j&lt;str.length;j++){
							var s=str[j].split("_");
							attrs+=s[0]+"_";
							if(s[0]==dd[i].title){
								attrs+=s[1]+":";
								break;
							}

						}
							if(s[1]==dd[i].textContent){
							if(j!=str.length){
								attrvalue+=":"
							}
							}
						* */
					}

					 str.forEach((item,index)=>{

					 	str.forEach((newItem,newIndex)=>{
					 		   if(newIndex>index){
					 		   	   if(str[index].attrId==str[newIndex].attrId){
					 		   	   	      str[index]={attrId:str[index].attrId,attrValues:str[index].attrValues+":"+str[newIndex].attrValues}
								   }
					 		   	   str[index]=str[index];
							   }

						})

					 })
                     console.log(JSON.stringify(str))
					//继续循环
					for (var i = 0; i < str.length; i++) {
						for (var j = i + 1; j < str.length; j++) {
							if (str[i].attrId === str[j].attrId) {
								str.splice(j, 1);
								j--;
							}
						}
					}

					console.log(str);
					let stringattrsBystr="";
					str.forEach((item,index)=>{
						stringattrsBystr+="&attrs="+item.attrId+"_"+item.attrValues;
					})
                  console.log(stringattrsBystr);
					var keyword=$('#keyword').val();
					if(keyword!=""){
						//alert(1);
						//判断搜索是否已经存在，如果存在了则替换
							this.url+="&keyword="+keyword;

					}
					if(stringattrsBystr!=""){
						this.url+=stringattrsBystr;
						console.log("我是最详细的url地址"+this.url)
					}

					//排序等规则

					var sort=$('#sort').find('.first').text();
				//	alert(sort)

					if(sort=="销量排序"){

						this.url+="&sort=saleCount_desc";
					}else if(sort=="价格优先"){

						this.url+="&sort=skuPrice_desc";
					}
					if(this.url.indexOf("&page")==-1){
						this.url+="&page=1"
					}

					if(this.url.substring(0,1)=="&"){
						//	alert(url.replace(/&/,"?"));
						this.url=this.url.replace(/&/,"?");
					}


					axios.get(glodate.serverZuul+"search/SearchParam"+this.url).then(response=>{
						//	console.log(response.data);
						$('#ddyixuan').css("display","none");//清空已选字符
						this.result=response.data;
					//	console.log("我是发过请求的地址"+this.url)
						//console.log("我是返回的面包屑"+JSON.stringify(this.result.navs))
						let linkurl="";
						this.result.navs.forEach(item=>{
							linkurl+="&attrs="+item.link;
						})
						this.url=linkurl;
						//console.log('我是地址'+this.url)
						$('.skusort').removeClass("first");//移除属性
						$('#ddvalue').html("");
						$('.attrValue').removeClass("selected")
						//	location.reload();
						//	this.keyWord=123;

						if(this.result.catalogs[0]!=undefined){
							axios.get(glodate.serverZuul+"search/listSkuByCatalogId?catalog_id="+this.result.catalogs[0].catalogId).then(response=>{
								this.resultskuSan=response.data;
							})
						}



					})

				},
				//面包屑
				onCrumbs(crumbsThis){
					this.result.navs.forEach((item,index)=>{
						if(item===crumbsThis){
							this.result.navs.splice(index,1);
						}
					})
					let linkurl="";
					this.result.navs.forEach(item=>{
						linkurl+="&attrs="+item.link;
					})
					this.url=linkurl;
					this.searchKey();
				},
				//前台传来的分类或者品牌，生成的tags
				onHome(){
				        //清空页面
					$('#brandOrCatelog').html("");
					location.href="../home/search.html";
				},
				//分页,默认传当前页码
				pagechange(page){
					alert(page);
					this.url+="&page="+page;
					this.searchKey();
				},



			}
		});
	})



		//获取属性值
		$('.attrValue').live('click',function (){

			var attrId=$(this).find("span").text();
			     if($(this).hasClass("selected")){
					 $(this).removeClass("selected");

					 var value=$(this).find("a").html();
					 var dd=$('#ddvalue').children("dd");
					 alert(dd.length);
					 if(dd.length==1){
						 $('#ddyixuan').css("display","none");
					 }
					 for(var i=0;i<dd.length;i++){
						 if(dd[i].textContent==value){
							 dd[i].remove();

						 }
					 }

					 //移除数组里的值
					 for(var j=0;j<str.length;j++){
					 	 if(str[j]==attrId+"_"+$(this).find("a").html()){
					 	 	str.splice(j,1);
					 	 	break;
						 }
					 }

				 }else{
					 $(this).addClass("selected");

				      str.push(attrId+"_"+$(this).find("a").html());
					 $('#ddyixuan').css("display","block");


					$('#ddvalue').append('<dd title="'+attrId+'" class="select-no selected"><a href="#">'+$(this).find("a").html()+'</a></dd>')


				 }


			return false;
		})


		//额外条件
		$('.skusort').live('click',function (){

			$('.skusort').removeClass("first");
			$('.skusort').css("background-color","white");
			if($(this).hasClass("skusort")){
				$(this).addClass("first");
				$(this).css("background-color","#4ABAE1");
			}
			vue1.searchKey();


			return false;
		})



</script>
